﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;

namespace UWP.Douban.Utils
{
    public static class StorageUtil
    {
        private const string ConfigName = "config.json";

        public static async Task<string> GetConfig()
        {
            var storageFile = await GetStorageFile(ConfigName);

            return await FileIO.ReadTextAsync(storageFile);
        }


        public static async Task SetConfig(string content)
        {
            var storageFile = await GetStorageFile(ConfigName);

            await FileIO.WriteTextAsync(storageFile, content);
        }


        private static async Task<StorageFile> GetStorageFile(string fileName)
        {
            var storageFolder = ApplicationData.Current.LocalFolder;
            return await storageFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
        }
    }
}
